//
//  HMPulldownView.swift
//  Weibo
//
//  Created by 唐润欣 on 16/6/19.
//  Copyright © 2016年 唐润欣. All rights reserved.
//

import UIKit
import HMRefresh

class HMPulldownView: UIView, HMRefreshViewDelegate {

    var pullDownBackgroundImage: UIImageView?
    
    /// 下拉提示图像
    var pulldownIcon: UIImageView?
    
    /// 刷新指示器
    var refreshIndicator: UIActivityIndicatorView?
    
    /// 提示标签
    var tipLabel: UILabel?
    
    /// 刷新时间标签
    var timeLabel: UILabel?
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HMPulldownView {
    
    func setupUI() {
        
        pullDownBackgroundImage = UIImageView(imageName: "refreshbg")
        pulldownIcon = UIImageView(imageName: "pull_refresh")
        refreshIndicator = UIActivityIndicatorView()
        
        tipLabel = UILabel(text: "下拉刷新", fontSize: 14)
        timeLabel = UILabel(text: "上拉刷新", fontSize: 14)
        
        addSubview(pullDownBackgroundImage!)
        addSubview(pulldownIcon!)
        addSubview(refreshIndicator!)
        addSubview(tipLabel!)
        addSubview(timeLabel!)
        
        //设置自动布局
        pullDownBackgroundImage?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(400)
        })
        
        pulldownIcon?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.left.equalTo(self).offset(120)
            make.centerY.equalTo(-11)
        })
        
        refreshIndicator?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.left.equalTo(self).offset(120)
            make.centerY.equalTo(-11)
        })
        
        tipLabel?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.left.equalTo(self).offset(150)
            make.centerY.equalTo(-22)
        })
        
        timeLabel?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.left.equalTo(self).offset(150)
            make.centerY.equalTo(-1)
        })
    }
}
